home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Unix / sys⁄file.h < prev    next >
Encoding:
Text File  |  1987-08-12  |  3.0 KB  |  118 lines  |  [TEXT/MPS ]

  1. /*    @(#)file.h 1.1 85/05/30 SMI; from UCB 6.2 83/09/23    */
  2.  
  3. #ifdef KERNEL
  4. /*
  5.  * Descriptor table entry.
  6.  * One for each kernel object.
  7.  */
  8. struct    file {
  9.     int    f_flag;        /* see below */
  10.     short    f_type;        /* descriptor type */
  11.     short    f_count;    /* reference count */
  12.     short    f_msgcount;    /* references from message queue */
  13.     struct    fileops {
  14.         int    (*fo_rw)();
  15.         int    (*fo_ioctl)();
  16.         int    (*fo_select)();
  17.         int    (*fo_close)();
  18.     } *f_ops;
  19.     caddr_t    f_data;        /* ptr to file specific struct (vnode/socket) */
  20.     off_t    f_offset;
  21.     struct    ucred *f_cred;    /* credentials of user who opened file */
  22. };
  23.  
  24. struct    file *file, *fileNFILE;
  25. int    nfile;
  26. struct    file *getf();
  27. struct    file *falloc();
  28. #endif
  29.  
  30. /*
  31.  * flags- also for fcntl call.
  32.  */
  33. #define    FOPEN        (-1)
  34. #define    FREAD        00001        /* descriptor read/receive'able */
  35. #define    FWRITE        00002        /* descriptor write/send'able */
  36. #ifndef    F_DUPFD
  37. #define    FNDELAY        00004        /* no delay */
  38. #define    FAPPEND        00010        /* append on each write */
  39. #endif
  40. #define    FMARK        00020        /* mark during gc() */
  41. #define    FDEFER        00040        /* defer for next gc pass */
  42. #ifndef    F_DUPFD
  43. #define    FASYNC        00100        /* signal pgrp when data ready */
  44. #endif
  45. #define    FSHLOCK        00200        /* shared lock present */
  46. #define    FEXLOCK        00400        /* exclusive lock present */
  47.  
  48. /* bits to save after open */
  49. #define    FMASK        00113
  50. #define    FCNTLCANT    (FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK)
  51.  
  52. /* open only modes */
  53. #define    FCREAT        01000        /* create if nonexistant */
  54. #define    FTRUNC        02000        /* truncate to zero length */
  55. #define    FEXCL        04000        /* error if already created */
  56.  
  57. #ifndef    F_DUPFD
  58. /* fcntl(2) requests--from <fcntl.h> */
  59. #define    F_DUPFD    0    /* Duplicate fildes */
  60. #define    F_GETFD    1    /* Get fildes flags */
  61. #define    F_SETFD    2    /* Set fildes flags */
  62. #define    F_GETFL    3    /* Get file flags */
  63. #define    F_SETFL    4    /* Set file flags */
  64. #define    F_GETOWN 5    /* Get owner */
  65. #define    F_SETOWN 6    /* Set owner */
  66. #endif
  67.  
  68. /*
  69.  * User definitions.
  70.  */
  71.  
  72. /*
  73.  * Open call.
  74.  */
  75. #define    O_RDONLY    000        /* open for reading */
  76. #define    O_WRONLY    001        /* open for writing */
  77. #define    O_RDWR        002        /* open for read & write */
  78. #define    O_NDELAY    FNDELAY        /* non-blocking open */
  79. #define    O_APPEND    FAPPEND        /* append on each write */
  80. #define    O_CREAT        FCREAT        /* open with file create */
  81. #define    O_TRUNC        FTRUNC        /* open with truncation */
  82. #define    O_EXCL        FEXCL        /* error on create if file exists */
  83.  
  84. /*
  85.  * Flock call.
  86.  */
  87. #define    LOCK_SH        1    /* shared lock */
  88. #define    LOCK_EX        2    /* exclusive lock */
  89. #define    LOCK_NB        4    /* don't block when locking */
  90. #define    LOCK_UN        8    /* unlock */
  91.  
  92. /*
  93.  * Access call.
  94.  */
  95. #define    F_OK        0    /* does file exist */
  96. #define    X_OK        1    /* is it executable by caller */
  97. #define    W_OK        2    /* writable by caller */
  98. #define    R_OK        4    /* readable by caller */
  99.  
  100. /*
  101.  * Lseek call.
  102.  */
  103. #define    L_SET        0    /* absolute offset */
  104. #define    L_INCR        1    /* relative to current offset */
  105. #define    L_XTND        2    /* relative to end of file */
  106.  
  107. #ifdef KERNEL
  108. #define    GETF(fp, fd) { \
  109.     if ((unsigned)(fd) >= NOFILE || ((fp) = u.u_ofile[fd]) == NULL) { \
  110.         u.u_error = EBADF; \
  111.         return; \
  112.     } \
  113. }
  114.  
  115. #define    DTYPE_VNODE    1    /* file */
  116. #define    DTYPE_SOCKET    2    /* communications endpoint */
  117. #endif
  118.